package com.ygq.controller;

import DO.EncodeTestDataTypeDO;
import DTO.*;
import VO.EncodeExampleVO;
import VO.EncodeTestVO;
import com.ygq.EncodeQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import result.PageResult;
import result.Result;

import java.util.List;

@RestController
@RequestMapping("/teacher/encode")
public class EncodeQuestionController {

    @Autowired
    private EncodeQuestionService encodeQuestionService;


    /**
     * 分页查询
     * @return
     */
    @PostMapping("/getEncodeQuestion")
    public Result<PageResult> getEncodeQuestion(@RequestBody PageJudgeQuestionDTO pageQuestionDTO){

        PageResult pageResult = encodeQuestionService.getEncodeQuestion(pageQuestionDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改编程题
     * @param updateEncodeQuestionDTO
     * @return
     */
    @PutMapping("/updateQuestion")
    public Result<String> updateQuestion(@RequestBody UpdateEncodeQuestionDTO updateEncodeQuestionDTO){
        encodeQuestionService.updateEncodeQuestion(updateEncodeQuestionDTO);
        return Result.success("ok");
    }

    /**
     * 获取结果示例的数量
     * @param id
     * @return
     */
    @GetMapping("/getEncodeExampleNumber")
    public Result<Integer> getEncodeExampleNumber(Integer id){
        return Result.success(encodeQuestionService.getEncodeExampleNumberByEncodeId(id));
    }

    /**
     * 根据id获取该题目的该序号的结果用例
     * @param id
     * @return
     */
    @GetMapping("/getEncodeExample")
    public Result<EncodeExampleVO> getEncodeExample(Integer id,Integer order){
        EncodeExampleVO encodeExampleVO = encodeQuestionService.getEncodeExampleByEncodeId(id,order);
        return Result.success(encodeExampleVO);
    }

    /**
     * 修改结果示例
     *
     */
    @PutMapping("/updateEncodeExample")
    public Result<String> updateEncodeExample(@RequestBody UpdateEncodeExampleDTO updateEncodeExampleDTO){
        encodeQuestionService.UpdateEncodeExampleById(updateEncodeExampleDTO);
        return Result.success("修改成功");
    }

    /**
     * 删除结果示例
     * @param id
     * @return
     */
    @DeleteMapping("/deleteEncodeExample")
    public Result<String> deleteEncodeExample(Integer id,Integer encodeId){
        encodeQuestionService.deleteEncodeExample(id,encodeId);
        return Result.success("ok");
    }

    /**
     * 添加结果示例
     * @param addEncodeExampleDTO
     * @return
     */
    @PutMapping("/AddEncodeExample")
    public Result<String> AddEncodeExample(@RequestBody AddEncodeExampleDTO addEncodeExampleDTO){
        encodeQuestionService.AddEncodeExample(addEncodeExampleDTO);
        return Result.success("ok");
    }

    /**
     * 获取数据信息
     * @return
     */
    @GetMapping("/getType")
    public Result<List<EncodeTestDataTypeDO>> getType(){
        return Result.success(encodeQuestionService.getType());
    }

    /**
     * 获取测试用例的数量
     * @param id
     * @return
     */
    @GetMapping("/getEncodeTestNumber")
    public Result<Integer> getEncodeTestNumber(Integer id){
        return Result.success(encodeQuestionService.getEncodeTestNumber(id));
    }


    /**
     * 获取测试用例数据
     * @param order
     * @param id
     * @return
     */
    @GetMapping("/getEncodeTest")
    public Result<EncodeTestVO> getEncodeTest(Integer order,Integer id){
        return Result.success(encodeQuestionService.getEncodeTest(id,order));
    }

    /**
     * 修改测试用例
     * @param updateEncodeTestDTO
     * @return
     */
    @PutMapping("/updateEncodeTest")
    public Result<String> updateEncodeTest(@RequestBody UpdateEncodeTestDTO updateEncodeTestDTO){
        encodeQuestionService.updateEncodeTest(updateEncodeTestDTO);
        return Result.success("ok");
    }

    /**
     * 删除测试用例
     * @param id， 该测试用例的id
     * @return
     */
    @DeleteMapping("/deleteEncodeTest")
    public Result<String> deleteEncodeTest(Integer id){
        encodeQuestionService.deleteEncodeTest(id);
        return Result.success("ok");
    }


    /**
     * 添加测试用例
     * @return
     */
    @PostMapping("/AddEncodeTest")
    public Result<String> AddEncodeTest(@RequestBody UpdateEncodeTestDTO updateEncodeTestDTO){
        encodeQuestionService.addTest(updateEncodeTestDTO);
        return Result.success("ok");
    }

    /**
     * 添加编程题
     * @param addEncodeDTO
     * @return
     */
    @PostMapping("/addencode")
    public Result<String> addencode(@RequestBody AddEncodeDTO addEncodeDTO){
        encodeQuestionService.addEncode(addEncodeDTO);
        return Result.success("ok");
    }
}
